package Leetcode.StackAndQueue.largestRectangleArea84;

/**
 * 暴力解法2 时间复杂度O（n^2）
 *
 * 用时1413ms
 *
 * 该暴力方法可复习
 */
public class Solution2 {
    public int largestRectangleArea(int[] heights) {
        int n = heights.length;
        int maxArea = 0;
        if(n == 0 || heights == null) {
            return 0;
        }
        for(int i = 0; i < n; i++) {
            int left = i;
            int right = i;
            while(left - 1 >= 0 && heights[left - 1] >= heights[i]) {
                left--;
            }
            while(right + 1 < n && heights[right + 1] >= heights[i]) {
                right++;
            }
            maxArea = Math.max(maxArea,(right - left + 1) * heights[i]);
        }

        return maxArea;
    }

    public static void main(String[] args) {
        int nums[] = {0,9};
        Solution2 solution = new Solution2();
        System.out.println(solution.largestRectangleArea(nums));
    }


}
